package cn.q3c.smzdm.client;

import java.util.Properties;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Value;

import cn.keyvalue.ccf.common.http.RequestUtils;
import cn.q3c.smzdm.bean.Crawler;

public class SmzdmApi {

	@Value("${REMOTE_Crawler_URL}")
	public static String REMOTE_Crawler_URL = "";
	@Value("${REMOTE_Images_URL}")
	public static String REMOTE_Images_URL = "";
	
	/**
	 * 上传抓取的内容
	 * @param crawler
	 * @throws Exception
	 */
	public static void rsyncCrawler( Crawler crawler ) throws Exception
	{
		Properties pro = new Properties();
		pro.put("content", StringUtils.trimToEmpty(crawler.getContent()));
		pro.put("description", StringUtils.trimToEmpty(crawler.getDescription()));
		pro.put("keywords", StringUtils.trimToEmpty(crawler.getKeywords()));
		pro.put("title", StringUtils.trimToEmpty(crawler.getTitle()));
		pro.put("udate", Long.toString(crawler.getUdate().getTime()));
		pro.put("url", StringUtils.trimToEmpty(crawler.getUrl()));
		pro.put("cdate", Long.toString(crawler.getCdate().getTime()));
		pro.put("source", Integer.toString(crawler.getSource()));
		
		RequestUtils.urlToStr(REMOTE_Crawler_URL, "GBK", pro);
	}	
	
	/**
	 * 通知服务器下载图片
	 * @param imageurl
	 * @param source
	 * @throws Exception
	 */
	public static void rsyncImages( String imageurl, Integer source ) throws Exception
	{
		Properties pro = new Properties();
		pro.put("imageurl", StringUtils.trimToEmpty(imageurl));
		pro.put("source", Integer.toString(source));
		
		RequestUtils.urlToStr(REMOTE_Images_URL, "GBK", pro);
	}

}
